<extend name="public/body" />
<block name="body">
    <div class="special_box">
        <div class="project_info_box card">
            <div class="card-body">
                <h6 class="navbar card-title">
                    <?=$info['title']?>
                    <ul class="navbar-nav float-right">
                        <li class="nav-item dropdown">
                            <a class="nav-link" href="javascript:void(0);" id="person_menu" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></a>
                            <div class="dropdown-menu" aria-labelledby="person_menu">
                                <?php
                                    if(session('member_id')==$info['member_id']){
                                ?>
                                <a class="dropdown-item" href="<?=url('Index/edit',['id'=>$info['id']])?>">设置</a>
                                <a class="dropdown-item" href="<?=url('Index/del',['project_id'=>$info['id']])?>">删除</a>
                                <?php
                                    }else{
                                ?>
                                <a class="dropdown-item" href="<?=url('Index/quit',['project_id'=>$info['id']])?>">退出</a>
                                <?php
                                    }
                                ?>
                            </div>
                        </li>
                    </ul>
                </h6>
                <div class="card-subtitle">
                    <div><?=htmlspecialchars_decode($info['remark'])?></div>
                    <div class="row">
                        <span class="creater col-lg-2 col-12">创建人：<?=$member_data[$info['member_id']]?></span>
                        <span class="time col-lg-3 col-12">创建时间：<?=$info['add_time']?></span>
                        <span class="time col-lg-7 col-12">外部访问地址：
                            <a href="<?=url('Api/external',['unique_code'=>$info['unique_code']],true,true)?>"><?=url('Api/external',['unique_code'=>$info['unique_code']],true,true)?></a>
                            <?php
                                if(session('member_id')==$info['member_id']){
                            ?>
                            <a href="<?=url('Index/generate',['project_id'=>$info['id']])?>" class="btn btn-sm btn-outline-danger ajax-get">重新生成</a>
                            <?php
                                }
                            ?>
                        </span>
                    </div>
                </div>
                <a href="<?=url('Api/index',['project_id'=>$info['id']])?>" class="btn btn-primary btn-sm">进入API列表</a>
            </div>
        </div>
        <h6 class="card-title">
            项目成员
            <?php
                if(session('member_id')==$info['member_id']){
            ?>
            <ul class="navbar-nav float-right">
                <li class="nav-item">
                    <a class="nav-link" href="javascript:void(0);" data-toggle="modal" data-target="#add_member"><img src="__IMG__/add_member.png" alt=""></a>
                </li>
            </ul>
            <?php
                }
            ?>
        </h6>
        <div class="project_member row">
            <div class="col-lg-3 col-md-4 col-6">
                <div class="card">
                    <div class="card-body row">
                        <div class="col-2">
                            <img src="__IMG__/cache/cover.jpeg" alt="">
                        </div>
                        <div class="col-10">
                            <h6 class="card-title">
                                <?=$member_data[$info['member_id']]?>
                                <span class="badge badge-success">创建者</span>
                            </h6>
                            <div class="card-subtitle">
                                加入时间：<?=$info['add_time']?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <?php
                foreach($project_member as $row){
            ?>
            <div class="col-lg-3 col-md-4 col-6">
                <div class="card">
                    <div class="card-body row">
                        <div class="col-2">
                            <img src="__IMG__/cache/cover.jpeg" alt="">
                        </div>
                        <div class="col-10">
                            <h6 class="navbar card-title">
                                <?=$member_data[$row['member_id']]?>
                                <ul class="navbar-nav float-right">
                                    <li class="nav-item dropdown">
                                        <a class="nav-link" href="#" id="join_<?=$row['id']?>" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></a>
                                        <div class="dropdown-menu" aria-labelledby="join_<?=$row['id']?>">
                                            <a class="dropdown-item ajax-get" href="<?=url('Index/remove',['project_id'=>$info['id'],'member_id'=>$row['member_id']])?>">移除</a>
                                        </div>
                                    </li>
                                </ul>
                            </h6>
                            <div class="card-subtitle">
                                加入时间：<?=$row['update_time']?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <?php
                }
            ?>
        </div>
    </div>
</block>
<block name="js">
    <!-- Modal -->
    <div class="modal fade" id="add_member" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg modal-dialog-scrollable" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">添加项目成员</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <input class="form-control search_member" type="text" name="search_member" placeholder="输入用户名或手机号码后回车即可搜索">
                    <div class="js_member_list member_list">
                        <div style="padding:5rem 0;text-align:center;color:#999;">请输入用户名或手机号码进行搜索</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
    $(function(){
        $("input[name=search_member]").on("change",function(){
            if($(this).val()=="") return false;
            $.get("<?=url('Index/search_member',['project_id'=>$info['id']])?>",{"search":$(this).val()},function(res){
                var html='';
                var data=res.data;
                for(var i=0;i<data.length;i++) {
                    html += `
                        <div class="card">
                            <div class="card-body">
                                <div>`+data[i].nickname+`</div>
                                <div class="clearfix">
                                    `+data[i].mobile+(data[i].is_join==1?'<a href="javascript:void(0);" class="btn btn-sm btn-outline-secondary disabled float-right">已加入</a>':'<a class="js_add_member btn btn-sm btn-outline-primary float-right" href="<?=url('Index/add_member')?>?project_id=<?=$info['id']?>&member_id='+data[i].id+'">添加</a>')+`
                                </div>
                            </div>
                        </div>`;
                }
                $(".js_member_list").html(html);
            })
        })
        $('#add_member').on('hidden.bs.modal', function (e) {
            $("input[name=search_member]").val("");
            $(".js_member_list").html('<div style="padding:5rem 0;text-align:center;color:#999;">请输入用户名或手机号码进行搜索</div>');
        })
        $(document).on("click",".js_add_member",function(e){
            e.preventDefault();
            var _this=$(this);
            $.get(_this.attr("href"),function(res){
                if(res.code==1){
                    _this.attr("href","javascript:void(0);");
                    _this.addClass("btn-outline-secondary disabled").html("已加入");
                    _this.removeClass("btn-outline-primary js_add_member");
                }else{
                    mytips.error(res.msg);
                }
            })
        })
    })
    </script>
</block>
